Imports System
Imports System.net
Imports System.Drawing 
Imports System.Drawing.Imaging 
Imports System.IO 

Public Partial Class SavePicture 
    Inherits System.Web.UI.Page 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            Me.SaveToPic()
        End If
    End Sub
    
    Private Sub SaveToPic()
        Try
            Dim img As System.Drawing.Image = Bitmap.FromStream(Request.InputStream)
            'Dim filePath As [String] = Server.MapPath(String.Format("~/{0:yyyyMMdd}.jpg", DateTime.Now))
            'img.Save(filePath, ImageFormat.Jpeg)

            Dim MyBitmap As Bitmap = New Bitmap(img, "80", "100")
            img.Dispose()

            Dim ms As MemoryStream = New MemoryStream()
            MyBitmap.Save(ms, ImageFormat.Png)
            Me.MyImage = ms
            MyBitmap.Dispose()

            Response.ClearContent()
            Response.AppendHeader("Content-Disposition", "attachment; filename=Personal.jpg")
            Response.ContentType = "image/Jpeg"
            Response.BinaryWrite(Me.MyImage.ToArray())
        Catch ex As Exception

        End Try
    End Sub

    Public Property MyImage() As MemoryStream
        Get
            Return Session("MyImage")
        End Get
        Set(ByVal value As MemoryStream)
            Session("MyImage") = value
        End Set
    End Property

End Class 